<template>
<div>
        <!-- 顶部新增 -->
      <div class="ji-biao">
        <span style="font-size: 12px; color: pink"
          >说明：目前支持学科和关键字条件筛选</span
        >
        <el-button type="success" size="small" icon="el-icon-edit" @click="$router.push('/questions/new')"
          >新增试题</el-button
        >
      </div>
  <el-form ref="form" size="small" :model="form" label-width="80px">
    <el-row>
      <el-col :span="6">
        <el-form-item label="学科">
          <el-select @change="changeFn" v-model="value.subjectID" placeholder="请选择">
               <el-option
                v-for="item in form.questions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="二级目录">
          <el-select v-model="value.catalogID" placeholder="请选择">
             <el-option
                v-for="item in form.directorys"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="标签">
          <el-select v-model="value.tags" placeholder="请选择">
             <el-option
                v-for="item in form.tags"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="关键字">
          <el-input v-model="value.keyword" placeholder="请输入题干搜索"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <el-form-item label="试题类型">
          <el-select v-model="value.questionType" placeholder="请选择">
            <el-option label="单选" value="1"></el-option>
            <el-option label="多选" value="2"></el-option>
            <el-option label="简答" value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="难度">
          <el-select v-model="value.difficulty" placeholder="请选择">
            <el-option label="简单" value="1"></el-option>
            <el-option label="一般" value="2"></el-option>
            <el-option label="困难" value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="方向">
          <el-select v-model="value.direction" placeholder="请选择">
            <el-option v-for="(itm,i) in direction" :key="i" :label="itm" :value="itm"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="录入人">
          <el-select v-model="value.creatorID" placeholder="请选择">
            <el-option v-for="itm in form.userName" :key="itm.id" :label="itm.username" :value="itm.username"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <el-form-item label="题目备注">
          <el-input v-model="value.remarks"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="企业简称">
          <el-input v-model="value.shortName"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="城市">
          <template>
            <el-select @change="changAddFn" style="width: 48%;margin-right: 2%;" v-model="value.province" placeholder="请选择">
              <el-option v-for="(item,index) in cities" :key="index" :label="item" :value="item">
              </el-option>
            </el-select>
            <el-select
            v-model="value.city"
              style="width: 50%;"
              placeholder="请选择"
            >
              <el-option v-for="(item,index) in citie" :key="index" :label="item" :value="item">
              </el-option>
            </el-select>
          </template>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item style=" text-align: right;">
          <el-button @click="onDelFn">清除</el-button>
          <el-button type="primary" @click="onGetFn" >搜索</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>

</div>
</template>

<script>
// 学科
import { simple } from '@/api/hmmm/subjects'
// 二级目录
import { simple as simples } from '@/api/hmmm/directorys'
// 标签
import { simple as simpleb } from '@/api/hmmm/tags'
// 管理员
import { simple as simpler } from '@/api/base/users'
// 地区
import { provinces, citys } from '@/api/hmmm/citys'
export default {
  data () {
    return {
      value: {
        subjectID: '',
        catalogID: '',
        tags: '',
        keyword: '',
        questionType: '',
        difficulty: '',
        direction: '',
        creatorID: '',
        province: '',
        city: '',
        remarks: '',
        shortName: ''
      },
      form: {
        questions: [],
        directorys: [],
        tags: [],
        userName: []
      },
      cities: provinces(),
      citie: [],
      direction: ['o2o', '外包服务', '企业服务', '互联网金融', '企业咨询', '互联网', '电子商务', '其他']
    }
  },
  async mounted () {
    const res = await simple()
    this.form.questions = res.data
    const arr = await simpler()
    this.form.userName = arr.data
  },
  methods: {
    changAddFn (type) {
      this.value.city = ''
      this.citie = citys(type)
    },
    async changeFn (type) {
      const res = await simples({ subjectID: type })
      this.form.directorys = res.data
      const arr = await simpleb({ subjectID: type })
      this.form.tags = arr.data
    },
    onDelFn () {
      this.value = {
        subjectID: '',
        catalogID: '',
        tags: '',
        keyword: '',
        questionType: '',
        difficulty: '',
        direction: '',
        creatorID: '',
        province: '',
        city: ''
      }
      this.form.directorys = []
      this.form.tags = []
    },
    onGetFn () {
      this.$emit('on-get-fn', this.value)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-select{
    width: 100%;
}
.ji-biao {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}
</style>
